package event

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/admin-api/pkg/code"
	"gitee.com/liuxuezhan/ar-platform/rpc-client/setting/client/event"
	"github.com/zeromicro/go-zero/core/logc"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type EventInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 详情
func NewEventInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EventInfoLogic {
	return &EventInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *EventInfoLogic) EventInfo(req *types.EventInfoReq) (resp *types.EventListResItem, err error) {
	if req.Id == 0 {
		return nil, code.ParamsInvalid
	}

	u, err := l.svcCtx.SettingService.EventService.EventInfo(l.ctx, &event.EventInfoReq{Id: req.Id})
	if err != nil {
		logc.Error(l.ctx, "AddEvent err:", err)
		return nil, err
	}

	if u.Code != int64(code.SettingRpcSuccessful.Code()) {
		return nil, code.BusinessFailure
	}

	resp = &types.EventListResItem{
		Id:         u.Data.Id,         // 主键
		MerchantId: u.Data.MerchantId, // 商户ID
		BrandType:  u.Data.BrandType,  // 厂商类型
		BrandName:  u.Data.BrandName,  // 厂商名称
		EventNum:   u.Data.EventNum,   // 事件编码
		ApiUrl:     u.Data.ApiUrl,     // api_url
		ApiToken:   u.Data.ApiToken,   // api_token
		Sort:       u.Data.Sort,       // 排序
		Status:     u.Data.Status,     // 状态,0:关,1:开
		OperatorId: u.Data.OperatorId, // 操作人id
	}
	return resp, nil
}
